<template>
  <div>
    <h1>login</h1>
    <form action="">
      <p>
        <input type="text" v-model="user.username" />
      </p>
      <p>
        <input type="text" v-model="user.password" />
      </p>
      <button @click="loginHandle">login</button>
    </form>
    <div>
      <router-link to="/home">go_home</router-link>
    </div>
  </div>
</template>

<script>
import { mapMutations, mapActions, mapState } from "vuex";
import { handleRouter } from "../router";
// import routerlist from "../tool/menu";
export default {
  data() {
    return {
      user: {
        username: "admin",
        password: "123456",
        role: "admin",
        routerlist: [],
      },
    };
  },
  mounted() {},
  computed: {
    ...mapState("user", ["routerlist"]),
  },
  methods: {
    ...mapActions("user", ["asyncGetUserdata"]),
    ...mapMutations("user", ["setuserdata", "setrouterlist"]),
    async loginHandle() {
      this.setuserdata(this.user);
      // 登陆成功 动态渲染路由
     await this.asyncGetUserdata();
      // console.log("kkl", this.routerlist);
      handleRouter(this.routerlist);
      this.$router.push("/home");
    },
  },
};
</script>

<style>
</style>